﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Qplus.Infrastructure;
using Qplus.protocol;
using Qplus.enums;
using System.Diagnostics;

namespace Qplus.UI
{
    public class ChatListener : IPacketListener
    {
        private static ChatListener instance;

        public event EventHandler<UIEvent> msgEvent;
        public event EventHandler<UIEvent> friendMsgEvent;
        public event EventHandler<UIEvent> strangerMsgEvent;

        public ChatListener()
        {

        }

        public static ChatListener Instance
        {
            get
            {
                if (null == instance)
                    instance = new ChatListener();
                return instance;
            }
            set { instance = value; }
        }

        public virtual void packetEvent(PacketEvent Pevent)
        {
            InPacket packet = Pevent.myPacket;
            if (packet == null)
            {
                return;
            }
            else
            {
                int id = packet.getMsgID();
                MMessageID MID = (MMessageID)packet.getMsgID();
                switch ((MMessageID)packet.getMsgID())
                {
                    case MMessageID.U2C_RESP_CHAT_SENDMSG:
                        {
                            Debug.WriteLine("U2C_RESP_CHAT_SENDMSG,发送消息回执");
                            break;
                        }
                    case MMessageID.U2C_NOTIFY_CHAT_RECVMSG:
                        {
                            Debug.WriteLine("U2C_NOTIFY_CHAT_RECVMSG,收到消息");

                            processMsgEvent();

                            break;
                        }
                    default:
                        break;
                }
            }
        }

        private void processMsgEvent()
        {
            if (null != msgEvent)
                msgEvent(this, new UIEvent());
        }
        private void processFriendMsgEvent()
        {
            if (null != friendMsgEvent)
                friendMsgEvent(this, new UIEvent());
        }
        private void processStrangerMsgEvent()
        {
            if (null != strangerMsgEvent)
                strangerMsgEvent(this, new UIEvent());
        }
    }
}
